package com.filex.ads.common;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;

import static android.content.Context.MODE_PRIVATE;

public class FilexSPHelper {

    public static final String DEFAULT_PREFERENCE_NAME = "sp_filex_ad";

    private FilexSPHelper() {}

    public static SharedPreferences getSharedPreferences(@NonNull final Context context) {
        Preconditions.checkNotNull(context);

        return context.getSharedPreferences(DEFAULT_PREFERENCE_NAME, MODE_PRIVATE);
    }

    public static SharedPreferences getSharedPreferences(
            @NonNull final Context context, @NonNull final String preferenceName) {
        Preconditions.checkNotNull(context);
        Preconditions.checkNotNull(preferenceName);

        return context.getSharedPreferences(preferenceName, MODE_PRIVATE);
    }

    public static void setString(Context context, String key, String value) {
        SharedPreferences sp = getSharedPreferences(context);
        sp.edit().putString(key, value).apply();
    }

    public static String getString(Context context, String key, String defVal) {
        return getSharedPreferences(context).getString(key, defVal);
    }
}
